<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表格全选</title>
    <style>
        table{
            border: 1px solid;
            width: 500px;
            margin-left: 30%;
        }

        td,th{
            text-align: center;
            border: 1px solid;
        }
        div{
            margin-top: 10px;
            margin-left: 30%;
        }
    </style>
    <script src="../js/jquery-1.11.0.js"></script>
<script>
    $(document).ready(function (){
        //按钮全选
        $("#selectAll").click(function (){
             $(".an").prop("checked",true)
        })
        //按钮全不选
        $("#unSelectAll").click(function (){
            $(".an").prop("checked",false)
        })

        //按钮反选
        $("#selectRev").click(function (){
         $()
        })
        //3个勾选框都选，上面的全选勾选框自动选
        var arr=$(".an");
        for (var i=1;i<arr.length;i++){
            $(arr[i]).click(function (){
                var count=0;
                for(var j=1;j<arr.length;j++){
                    if (arr[j].checked){
                        count++;
                    }
                }
                if(count==3){
                    arr[0].checked=true;
                }else{
                    arr[0].checked=false;
                }
            })
        }
    })
    //勾选框全选框
    function f(t){
        var b = t.checked;
        console.log(b)
        $(".an").prop("checked",b)
    }







</script>

</head>
<body>

<table>
    <caption>学生信息表</caption>
    <tr>
        <th><input type="checkbox"id="a" onclick="f(this)"  class="an"></th>
        <th>编号</th>
        <th>姓名</th>
        <th>性别</th>
        <th>操作</th>
    </tr>

    <tr>
        <td><input type="checkbox" id="a1"   class="an"></td>
        <td>1</td>
        <td>令狐冲</td>
        <td>男</td>
        <td><a href="javascript:void(0);">删除</a></td>
    </tr>

    <tr>
        <td><input type="checkbox" id="a2"  class="an"></td>
        <td>2</td>
        <td>任我行</td>
        <td>男</td>
        <td><a href="javascript:void(0);">删除</a></td>
    </tr>

    <tr>
        <td><input type="checkbox" id="a3"  class="an"></td>
        <td>3</td>
        <td>岳不群</td>
        <td>?</td>
        <td><a href="javascript:void(0);">删除</a></td>
    </tr>

</table>
<div>
    <input type="button" id="selectAll" value="全选">
    <input type="button" id="unSelectAll" value="全不选">
    <input type="button" id="selectRev" value="反选">
</div>
</body>
</html>